home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 14642 / 14642.xpi / chrome / content / import.js < prev    next >
Text File  |  2009-10-01  |  4KB  |  116 lines

  1. /* Copyright 2009, Boomtango.com.  All Rights Reserved. */
  2. /* import.js
  3.  * Responsible for importing history
  4.  */
  5. Components.utils.import("resource://boomtango/app.js");
  6. var btimport = {
  7.     onLoad: function(){
  8.         this.app = boomtangoApp;
  9.     },
  10.     _doClose: false,
  11.     _inImport: false,
  12.     /*
  13.     generateThumb: function(win){
  14.         var canvas = document.getElementById("boomtangoThumbGen");
  15.         return boomtangoApp.generateThumb(win, canvas);
  16.     },
  17.     */
  18.     loadContent: function(url, callback){
  19.         this.app.log("history::loadContent(" + url + ")");
  20.         var iframe  = document.getElementById("import.iframe");
  21.         if (iframe) {
  22.             iframe.style.height = "0px";
  23.             iframe.webNavigation.allowAuth = false;
  24.             iframe.webNavigation.allowImages = false;
  25.             iframe.webNavigation.allowJavascript = false;
  26.             iframe.webNavigation.allowMetaRedirects = true;
  27.             iframe.webNavigation.allowPlugins = false;
  28.             iframe.webNavigation.allowSubframes = false;
  29.             var self = this;
  30.             var func = function (e) { 
  31.                 self.app.log("history::loadContent -Loaded(" + url + ")");
  32.                 var doc = e.originalTarget;
  33.                 if(doc.nodeName == "#document"){
  34.                     iframe.removeEventListener("DOMContentLoaded", func, true);
  35.                     window.clearTimeout(timeoutid);
  36.                     callback(doc, "");
  37.                 }
  38.             };
  39.             iframe.addEventListener(
  40.                 "DOMContentLoaded", 
  41.                 func,
  42.                true
  43.             );
  44.             var failFunc = function(){
  45.                 iframe.removeEventListener("DOMContentLoaded", func, true);
  46.                 callback(null);
  47.             };
  48.  
  49.             var timeoutid = window.setTimeout(failFunc, 10*1000);
  50.             iframe.webNavigation.loadURI(url,Components.interfaces.nsIWebNavigation,null,null,null);
  51.         } else {
  52.             callback(null);
  53.         }
  54.     },
  55.     importfts: function(){
  56.         boomtangoApp.tracker.importBrowserHistoryStart();
  57.        
  58.         this._inImport = true;
  59.         var self = this;
  60.         var loadFunc = function(url, callback){
  61.             self.loadContent(url, callback);
  62.         };
  63.         var updateFunc = function(x, total, doContinue){
  64.             self.app.log("import::updateFunc(" + x + " of " + total + ": " + doContinue + ")");
  65.             document.getElementById('prog').value = 
  66.                 100 * x / total;
  67.             if(!doContinue || self._doClose){
  68.                 window.close();
  69.             } else {
  70.                 boomtangoApp.tracker.importBrowserHistoryDoFTS(updateFunc, loadFunc);
  71.             }
  72.         };
  73.         boomtangoApp.tracker.importBrowserHistoryDoFTS(updateFunc, loadFunc);
  74.     },
  75.     import: function(){
  76.         boomtangoApp.log("import::import");
  77.         var self = this;
  78.         boomtangoApp.tracker.importBrowserHistoryStart();
  79.  
  80.         var button = document.getElementById("importbutton");
  81.         button.setAttribute("label", boomtangoApp.getString("import.importing"));
  82.         button.setAttribute("disabled", "true");
  83.  
  84.         button = document.getElementById("closebutton");
  85.         button.setAttribute("label", boomtangoApp.getString("import.close"));
  86.        
  87.         this._inImport = true;
  88.         var func = function(){
  89.             var result = boomtangoApp.tracker.importBrowserHistoryDo(
  90.                 function(x, total){
  91.                     document.getElementById('prog').value = 
  92.                         100 * x / total;
  93.                     if(self._doClose){
  94.                         return false;
  95.                     } else {
  96.                         return true;
  97.                     }
  98.                 }
  99.             );
  100.             if(result){
  101.                 window.setTimeout(func, 0);
  102.             } else {
  103.                 window.close();
  104.             }
  105.         };
  106.         window.setTimeout(func, 0);
  107.     },
  108.     close: function() {
  109.         if(!this._inImport){
  110.             window.close();
  111.         } else {
  112.             this._doClose = true;
  113.         }
  114.     }
  115. };
  116.